番外編Agones FleetAutoscaleRequestMetaData & 軽いContribute編 今回からこのアドベントカレンダーの記事はCosenseに書いていきます。なんとなく気分です。
Agones FleetAutoscaleRequestMetaData & 軽いContribute編 ←今ここ
今日は番外編です。
せっかく全部ソースコード読んだのでIssueも眺めていたのですが、軽いDocs系くらいしかサクッとできるものがなさそうだったのでとりあえずDocsで記念Contributeしておきました。(OpenCensusからの移行とかおもろそうなのはあったんですが時間をかける必要がありそうなのでチマチマ見て行こうかなと思っています)
FleetAutoscaleRequestMetaDataに関して
この機能は先日リリースされた1.54.0でBetaへ昇格された機能です。ベータになるとフィーチャーゲートはデフォルトで有効になります。
機能としてはFleetのyamlで設定する labels と annotations が FleetAutoscaleRequest に含まれるようになり、Webhook経由のAutoScaleではは Fleet 固有のメタデータに基づいてスケーリングの判断を行えるようになります。(ちなみに今後実装予定のWasm AutoScaleの方でも使えるようになります)
code:go
type FleetAutoscaleRequest struct {
// UID is an identifier for the individual request/response. It allows us to distinguish instances of requests which are
// otherwise identical (parallel requests, requests when earlier requests did not modify etc)
// The UID is meant to track the round trip (request/response) between the Autoscaler and the WebHook, not the user request.
// It is suitable for correlating log entries between the webhook and apiserver, for either auditing or debugging.
UID types.UID json:"uid""
// Name is the name of the Fleet being scaled
Name string json:"name"
// Namespace is the namespace associated with the request (if any).
Namespace string json:"namespace"
// The Fleet's status values
Status v1.FleetStatus json:"status"
Labels mapstringstring json:"labels,omitempty" Annotations mapstringstring json:"annotations,omitempty" }
Autoscaleの各実装は下記を見てください。
Contributeに関して
Docsの更新だけなので大したContributeはしていないですが本体以外の部分に関しても触れておきます。
AgonesのドキュメントはHugoで作成されています。
HugoではFeature Gateの機能に関してはshortcodeのブロックでバージョンごとに表示・非表示の制御が行われています。
htmlのテンプレートが用意されており、現在のリリースバージョンがpublishVersion以上かつexpiryVersion未満の場合のみ、囲まれたコンテンツを表示する、といった制御がされます。
code:html
{{- with or (.Get "publishVersion") (.Get "expiryVersion")}}
{{- else }}
{{ errorf "missing value for either publishVersion or expiryVersion: %s" .Position}}
{{- end}}
{{- $publishVersion := (.Get "publishVersion" ) | default "0.0.0" }}
{{- $expiryVersion := (.Get "expiryVersion") | default "9999.0.0"}}
{{- $publDigits := split $publishVersion "." }}
{{- $curDigits := split $version "." }}
{{- $expDigits := split $expiryVersion "." }}
今回対応したのはこの辺です。
shortcodeがビルド時にバージョンを比較して、条件に合うコンテンツのみをHTMLに含めるような挙動になります。
code:mk
feature-shortcode-update: ensure-build-image
docker run --rm $(common_mounts) --workdir=$(mount_path) $(DOCKER_RUN_ARGS) $(build_tag) \
go run build/scripts/feature-shortcode-update/main.go -version=$(version)
なのでContributeする側はテンプレートに合わせてpublishVersionとexpiryVersionを追加箇所に記入してるあげで対応が完了します。非常に楽ですね。
CI/CDに関して
Google関連のOSSにContributeする際はCLAに署名する必要があります。(昔対応していたので割愛)
レビュー過程ではGoole Cloud Buildを使った実際のクラウド環境内でのビルドが行われます。(今回はdocsの更新なのであんまり関係はない)
レビュアーが/gcbrunと書き込むことで手動でトリガーするようにしているぽいです。
ちなみにこのビルドの中では下記のような検証が行われています。
コード生成の検証(CRD)
Lint
ビルド
SDK ビルド
ユニットテスト
ウェブサイトプレビュー生成
E2Eテスト(GKE)
Kubernetes 1.32 (generic) - us-west1
Kubernetes 1.33 (generic) - asia-east1
Kubernetes 1.34 (generic) - europe-west1
Kubernetes 1.32 (GKE Autopilot) - us-west1
Kubernetes 1.33 (GKE Autopilot) - asia-east1
Kubernetes 1.34 (GKE Autopilot) - europe-west1
モック等ではなく実際のGKEを利用したE2Eテストも行われています。
リソース
テスト内容
これによって各バージョンで実際の環境で動作検証を行い、ユーザーが安全にCustom Resourceを使えるような環境になっているんだなあと思いました。
まとめ
ここまでAgonesを見ていきました、せっかくコードを全部読んだので継続的にコントリビュートできるように注視していこうと思います。